#include "thread_test.h"
#include <stdio.h>
#include <assert.h>

long step;

static void *f(void * arg)
{
	long i;
	long n = (long)arg;
	printf("in f(%ld) at line %d before loop\n", n, __LINE__);
	for(i = 0; i < n; i++) {
		printf("in f(%ld) at line %d before yielding at loop %ld\n", n, __LINE__, i);
		assert(!thread_yield());
		printf("in f(%ld) at line %d after yielding at loop %ld\n", n, __LINE__, i);
	}
	printf("in f(%ld) at line %d after loop\n", n, __LINE__);
	return NULL;
}


int main(int argc, char *argv[])
{
	thread_t t1, t2;
	printf("in main() at line %d before thread_create on f()\n", __LINE__);
	assert(!thread_create(&t1, f, (void*)1l));
	printf("in main() at line %d after thread_create on f() and before thread_create on f()\n", __LINE__);
	assert(!thread_create(&t2, f, (void*)2l));
	printf("in main() at line %d after thread_create on f() and before thread_join on f()\n", __LINE__);
	assert(!thread_join(t1, NULL));
	printf("in main() at line %d after thread_join on f() and before thread_join on f()\n", __LINE__);
	assert(!thread_join(t2, NULL));
	printf("in main() at line %d after thread_join on f() and before exiting\n", __LINE__);
	return 0;
}
